import { Form } from "react-router-dom";
import http from "./http"

// 获取今日新闻信息 & 轮播图信息
export const newsLatest = () => http.get("/api/news_latest")

// 获取往日新闻信息
export const queryNewsBefore = (time) => {
    return http.get('/api/news_before', {
        params: {
            time
        }
    });
};

// 获取新闻详细信息
export const queryNewsInfo = (id) => {
    return http.get('/api/news_info', {
        params: {
            id
        }
    });
};

// 获取新闻点赞信息
export const queryStoryExtra = (id) => {
    return http.get('/api/story_extra', {
        params: {
            id
        }
    });
};

//发送验证码
export const sendPhoneCode = (phone) => {
    return http.post("/api/phone_code", { phone })
}

// 登录/注册
export const login = (phone, code) => {
    return http.post('/api/login', {
        phone,
        code
    });
};

// 获取登录者信息
export const queryUserInfo = () => http.get('/api/user_info');

// 获取收藏列表
export const storeList = () => http.get('/api/store_list');

// 移除收藏
export const storeRemove = (id) => {
    return http.get('/api/store_remove', {
        params: {
            id
        }
    });
};

// 收藏新闻
export const store = (newsId) => {
    return http.post('/api/store', { newsId });
};

export const upload = (file) => {
    let fm = new FormData();
    fm.append("file", file);
    return http.post("/api/upload", fm)
}

// 修改个人信息
export const userUpdate = (username, pic) => {
    return http.post('/api/user_update', {
        username,
        pic
    });
};